home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / GMSMTH01.ZIP / INCLUDE / GUI.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-08  |  10.1 KB  |  436 lines

  1. /*
  2.    Copyright 1993, Alec Russell, ALL rights reserved
  3.  
  4.    FILE : gui.h - defines and structs for gui stuff, also see g_io.h
  5.           for event defines
  6.  
  7.           Also some simple font tracking stuff
  8.  
  9.    HISTORY:
  10.       created : may 25, 1993
  11.       updates :
  12.  
  13.       1995 - increased size of many strings. this was done before the lib
  14.              was released so it won't effect all you users.
  15.              DON'T use any structs with _old_ in the name.
  16.  
  17. */
  18.  
  19. #ifndef DEF_GUI
  20. #define DEF_GUI 1
  21.  
  22.  
  23. #include <g_def.h>
  24. #include <palette.h>
  25. #include <g_io.h>
  26.  
  27. /* NOTE!! all gui structs start off with this struct */
  28.  
  29. #if 0
  30. typedef struct
  31.    {
  32.    BYTE type;
  33.    BYTE gui_flags;
  34.    BYTE draw_flags;
  35.    BYTE status_flags;
  36.    USHORT id;
  37.    short  x, y, width, height;
  38.    BYTE   light_color, medium_color, dark_color;
  39.    }
  40. gui_t;
  41.  
  42. #endif
  43.  
  44.  
  45.  
  46. enum gui_types
  47.    {
  48.    GUI_RECT,
  49.    GUI_BUTTON,
  50.    GUI_TEXT,
  51.    GUI_STRING_INPUT,
  52.    GUI_SLIDER,
  53.    GUI_PLIST,
  54.    GUI_RADIO
  55.    };
  56.  
  57. enum thumb_pos
  58.    {
  59.    NOT_ON_SLIDER,
  60.    ON_THUMB,
  61.    BELOW_THUMB,
  62.    ABOVE_THUMB
  63.    };
  64.  
  65. #define GUI_MIN_THUMB 10
  66. #define LIST_TEXT_LEN 80
  67.  
  68. #define GUI_MAX_TEXT_OLD 50     // I increased this before lib release.
  69. #define GUI_MAX_TEXT     90
  70. #define GUI_MAX_BUTT_TEXT 50
  71. #define GUI_MAX_GADGET 50
  72. #define GUI_MAX_STACK  10
  73.  
  74. /* button draw flags */
  75. #define GUI_HAS_TEXT    1
  76. #define GUI_HAS_BITMAP  2
  77.  
  78. /* button gui_flags */
  79. #define GUI_TOGGLE      1
  80. #define GUI_TOUCH       2
  81. #define GUI_NORMAL      4
  82.  
  83.  
  84. /* text draw flags */
  85. #define GUI_NUMBERS_ONLY 1
  86. #define GUI_TEXT_INVIS   2
  87.  
  88. /* rect gui_flags */
  89. #define GUI_SAVE_UNDER   1
  90.  
  91. /* slider draw flags, used for radio button too */
  92. #define GUI_VERT 1       // else HORZ
  93.  
  94. // plist draw_flags
  95. #define MULTI_SELECT 1  // else single
  96.  
  97. /* common draw flags */
  98. #define GUI_INVISIBLE   64
  99.  
  100. #define common gui_flags */
  101. #define GUI_SELECTABLE  64
  102.  
  103.  
  104. /* status_flags */
  105. #define GUI_ACTIVE      1
  106. #define GUI_UP          2
  107. #define GUI_DOWN        4
  108. #define GUI_DRAG        8
  109.  
  110. /* a note on font id's
  111.  
  112. from xtext.h
  113.  
  114. #define FONT_8x8  0
  115. #define FONT_8x15 1
  116. #define FONT_USER 2
  117.  
  118. font ids of 0 and 1 are ROM fonts, ids greater than 1 are user defined
  119.  
  120. */
  121.  
  122. /* only ids of 2 or more are tracked by this, id's 0, and 1 are ROM fonts */
  123. #define GUI_MAX_FONT 4
  124.  
  125. typedef struct
  126.    {
  127.    BYTE id;        /* must be greater than 1 */
  128.    FARPTR font;
  129.    }
  130. font_list_t;
  131.  
  132. extern BYTE num_gui_fonts;
  133. extern font_list_t font_list[GUI_MAX_FONT];
  134.  
  135.  
  136. // the main rect everything sits on
  137. typedef struct
  138.    {
  139.    BYTE   type;
  140.    BYTE   gui_flags;
  141.    BYTE   draw_flags;
  142.    BYTE   status_flags;
  143.    USHORT id;
  144.    short  x, y, width, height;
  145.    BYTE   light_color, medium_color, dark_color;
  146.    }
  147. gui_rect_t;
  148.  
  149.  
  150. /* non-editable text - FOR TITLES etc... */
  151. typedef struct
  152.    {
  153.    BYTE   type;
  154.    BYTE   gui_flags;
  155.    BYTE   draw_flags;
  156.    BYTE   status_flags;
  157.    USHORT id;
  158.    short  x, y, width, height;
  159.    BYTE   light_color, medium_color, dark_color;
  160.    BYTE   text_color;
  161.    BYTE   font_id;
  162.    char   text[GUI_MAX_TEXT+1];
  163.    USHORT txt_x, txt_y;
  164.    }
  165. gui_text_t;
  166.  
  167. /* non-editable text - FOR TITLES etc... */
  168. typedef struct
  169.    {
  170.    BYTE   type;
  171.    BYTE   gui_flags;
  172.    BYTE   draw_flags;
  173.    BYTE   status_flags;
  174.    USHORT id;
  175.    short  x, y, width, height;
  176.    BYTE   light_color, medium_color, dark_color;
  177.    BYTE   text_color;
  178.    BYTE   font_id;
  179.    char   text[GUI_MAX_TEXT_OLD+1];
  180.    USHORT txt_x, txt_y;
  181.    }
  182. gui_text_old_t;
  183.  
  184. /* editable 
  185.  
  186. /* editable text */
  187. typedef struct
  188.    {
  189.    BYTE   type;
  190.    BYTE   gui_flags;
  191.    BYTE   draw_flags;
  192.    BYTE   status_flags;
  193.    USHORT id;
  194.    short  x, y, width, height;
  195.    BYTE   light_color, medium_color, dark_color;
  196.    BYTE   text_color;
  197.    BYTE   font_id;
  198.    char   text[GUI_MAX_TEXT_OLD+1];
  199.    USHORT txt_x, txt_y;
  200.    BYTE   cursor_x;
  201.    BYTE   max_len, curr_len;
  202.    }
  203. gui_input_old_t;
  204.  
  205.  
  206. /* editable text */
  207. typedef struct
  208.    {
  209.    BYTE   type;
  210.    BYTE   gui_flags;
  211.    BYTE   draw_flags;
  212.    BYTE   status_flags;
  213.    USHORT id;
  214.    short  x, y, width, height;
  215.    BYTE   light_color, medium_color, dark_color;
  216.    BYTE   text_color;
  217.    BYTE   font_id;
  218.    char   text[GUI_MAX_TEXT+1];
  219.    USHORT txt_x, txt_y;
  220.    BYTE   cursor_x;
  221.    BYTE   max_len, curr_len;
  222.    }
  223. gui_input_t;
  224.  
  225. // button stuff
  226. typedef struct
  227.    {
  228.    BYTE   text_color;
  229.    BYTE   hot_color;
  230.    BYTE   font_id;
  231.    short  x, y;
  232.    char   text[GUI_MAX_BUTT_TEXT+1];
  233.    }
  234. gui_txt_t;
  235.  
  236. typedef struct
  237.    {
  238.    short x, y;
  239.    USHORT width, height;
  240.    USHORT size_bitmap;
  241.    BYTE far *bitmap;       /* MUST be pbm type bitmap */
  242.    }
  243. gui_shape_t;
  244.  
  245. typedef union
  246.    {
  247.    gui_shape_t shape;
  248.    gui_txt_t text;
  249.    }
  250. button_data_u;
  251.  
  252. typedef struct
  253.    {
  254.    BYTE   type;
  255.    BYTE   gui_flags;
  256.    BYTE   draw_flags;
  257.    BYTE   status_flags;
  258.    USHORT id;
  259.    short  x, y, width, height;
  260.    BYTE   light_color, medium_color, dark_color;
  261.    short  hot_key;
  262.    button_data_u data;
  263.    }
  264. gui_button_t;
  265.  
  266. typedef struct
  267.    {
  268.    BYTE type;
  269.    BYTE gui_flags;
  270.    BYTE draw_flags;
  271.    BYTE status_flags;
  272.    USHORT id;
  273.    short x, y, width, height;
  274.    BYTE  light_color, medium_color, dark_color;
  275.    short th_size, th_top;   // top means left if horz
  276.    USHORT plist_id;  // 0 if no associated plist
  277.    }
  278. gui_slider_t;
  279.  
  280. typedef struct
  281.    {
  282.    BYTE type;
  283.    BYTE gui_flags;
  284.    BYTE draw_flags;
  285.    BYTE status_flags;
  286.    USHORT id;
  287.    short x, y, width, height;
  288.    BYTE  light_color, medium_color, dark_color;
  289.    short num_items;    // total number of items in list
  290.    short top_item;     // item at top of visible list
  291.    short cursor_item;  // cursor position
  292.    short page_items;   // number of items that fit in one page
  293.    BYTE  far *curr_items;  // list of item(s) selected
  294.    USHORT slider_id;   // MUST be defined!!!
  295.    char font_id;     // of text in list
  296.    BYTE fore_col, back_col;   // text color of unselected items
  297.    BYTE curs_fore, curs_back; // text color if cursor on it
  298.    BYTE sel_fore, sel_back;    // text color of selected items
  299.    BYTE both_fore, both_back;  // text color of selected items with cursor on it
  300.    char far *items;      // the list, every LIST_TEXT_LEN chars is a text item
  301.    }
  302. gui_plist_t;
  303.  
  304. typedef struct
  305.    {
  306.    BYTE type;
  307.    BYTE gui_flags;
  308.    BYTE draw_flags;
  309.    BYTE status_flags;
  310.    USHORT id;
  311.    short  x, y, width, height;
  312.    BYTE   light_color, medium_color, dark_color;
  313.    short num_buttons;
  314.    short active_button;
  315.    BYTE active_color, inactive_color;
  316.    }
  317. gui_radio_t;
  318.  
  319. typedef union
  320.    {
  321.    gui_rect_t     rect;
  322.    gui_text_t     text;
  323.    gui_button_t   button;
  324.    gui_input_t    input;
  325.    gui_slider_t   slider;
  326.    gui_plist_t    plist;
  327.    gui_radio_t    radio;
  328.    }
  329. gui_all_u;
  330.  
  331. // NOT the pick list, the list of currently loaded gadgets
  332. typedef struct
  333.    {
  334.    BYTE num_gadgets;
  335.    BYTE num;
  336.    short dx, dy, x1, y1;
  337.    gui_all_u *curr_gadget;  /* NULL if no current */
  338.    gui_all_u *gadget[GUI_MAX_GADGET];
  339.    }
  340. gui_list_t;
  341.  
  342. // default colours, fonts used for runtime creation of gadgets
  343. typedef struct
  344.    {
  345.    BYTE   light_color, medium_color, dark_color;
  346.    BYTE   text_color;
  347.    BYTE   font_id;
  348.    BYTE   hot_color;
  349.    }
  350. gui_default_t;
  351.  
  352. // used to save/restore gadgets in mem
  353. typedef struct
  354.    {
  355.    short num;
  356.    gui_list_t list[GUI_MAX_STACK];
  357.    }
  358. gui_stack_t;
  359.  
  360. /* colors - only valid for standard dark palette */
  361. #define BLACK   1
  362. #define BLUE    16
  363. #define GREEN   35
  364. #define YELLOW  47
  365. #define RED     55
  366. #define WHITE   15
  367. #define GREY    8
  368. #define BROWN   56
  369.  
  370. extern gui_default_t gui_def;
  371. extern gui_list_t gui_list;
  372. extern gui_stack_t gui_stack;
  373.  
  374. extern short m_width, m_height;
  375. extern char far *mouse;
  376. extern char far *mouse_all;
  377. extern BYTE want_slider_moves;
  378.  
  379. gui_all_u *get_id_gadget(short id);
  380. short gui_load_font(BYTE id, char *path);
  381. void gui_unload_all_fonts(void);
  382. void change_font(BYTE id);
  383. void gui_draw_rect(short dx, short dy, gui_all_u  *g, short up);
  384. void gui_draw_button(gui_button_t  *b);
  385. void gui_draw_text(gui_text_t  *t);
  386. void gui_edit_string(gui_input_t  *t, short a);
  387. void gui_draw_input(gui_input_t  *t);
  388. void gui_draw_gadget(void);
  389. void gui_unload_gadget(void);
  390. short gui_load_gadget(char *fname, char *font_path);
  391. short gui_do_gadget(event_t *event);
  392. short on_rect(event_t *event);
  393. short on_gadget(gui_all_u *g, event_t *event);
  394. void gui_stack_select(short num);
  395. void gui_push(void);
  396. void gui_pop(void);
  397. void gui_pop_all(void);
  398. void gui_unload_mouse(void);
  399. void gui_load_mouse(char *mouse_name);
  400. void gui_draw_mouse(void);
  401. void gui_hide_mouse(void);
  402. void gui_show_mouse(void);
  403. short gui_select_color(short old_color, char *exe_path);
  404. void mega_clear(void);
  405. void gui_one_button(short dx, short dy, char *button_text, char *s, BYTE hot_key);
  406. short gui_two_button(short dx, short dy, char *yes, char *no,
  407.                     char *s, BYTE hot1, BYTE hot2);
  408. short gui_three_button(short dx, short dy, char *one, char *two, char *three,
  409.                     char *s, BYTE hot1, BYTE hot2, BYTE hot3);
  410. short gui_get_string(short dx, short dy, char *yes, char *no,
  411.                     char *s, BYTE hot1, BYTE hot2, char *in,
  412.                     BYTE max_len, short min_width);
  413. void gui_display_text_file(char *fname, char *path);
  414. void gui_init_plist_file(gui_plist_t *p, char *fname);
  415. void gui_reinit_plist(gui_plist_t *p, char far *list, short num);
  416. void gui_reinit_plist_file(gui_plist_t *p, char *fname);
  417. void gui_init_plist(gui_plist_t *p, char far *list, short num);
  418. void set_gadget_colrs_to_def(short change_font);
  419. void set_gui_def_colors_to_gadget( short id );
  420. void gui_set_id_active(short id);
  421. void gui_set_next_active(void);
  422. void gui_set_prev_active(void);
  423. void centreText( gui_all_u *g );
  424. void setRadioBtnVal( short id, short val );
  425. short getRadioBtnVal( short id );
  426. void setGadgetText(short id, char *str, short n);
  427. void GadgetOnOff( short id, short On );
  428. char *get_gadget_text(short id, char *s, short n, short max);
  429. void set_clip_rect( short xMin, short xMax, short yMin, short yMax );
  430. char *nearFName( char far *farFName );
  431.  
  432. #endif
  433.  
  434. /* ------------------------------ end of file ------------------------- */
  435.  
  436.